<template>
  <div>
    <el-row>
      <el-col :span="24">
        <p class="pinformation" style="margin-top: 7px">搜索条件</p>
      </el-col>
    </el-row>
    <el-form label-width="100px" :model="queryParams" ref="queryRef">
      <el-row>
        <el-col :span="4">
          <el-form-item label="检测类别：" prop="jclbId">
            <el-select v-model="queryParams.jclbId" clearable>
              <el-option v-for="item in proxy.addListNoLimit(
                jclbList,
                'jclbId',
                'jclbName'
              )" :key="item.jclbId" :value="item.jclbId" :label="item.jclbName" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="点位名称：" prop="pointName">
            <el-input v-model="queryParams.pointName" clearable maxlength="100" @keyup.enter="handleQuery"
              placeholder="请输入点位名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="连测天数：" prop="sampleDay">
            <el-input v-model="queryParams.sampleDay" clearable maxlength="100" @keyup.enter="handleQuery"
              oninput="value=value.replace(/[^0-9]/g,'')" @blur="queryParams.sampleDay = $event.target.value"
              placeholder="请输入连测天数"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="每天频次：" prop="sampleCount">
            <el-input v-model="queryParams.sampleCount" clearable maxlength="100" @keyup.enter="handleQuery"
              oninput="value=value.replace(/[^0-9]/g,'')" @blur="queryParams.sampleCount = $event.target.value"
              placeholder="请输入每天频次"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="是否分包：" prop="isPackage">
            <el-col :span="4"><el-tooltip class="box-item" effect="customized" content="意为该方案中的某些检测项目为分包项目，但需己方采样。"
                placement="bottom">
                <svg-icon :icon-class="'wenhao'" class="mark" /> </el-tooltip></el-col>
            <el-col :span="20">
              <el-select clearable v-model="queryParams.isPackage">
                <el-option v-for="dict in isPackageList" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)" />
              </el-select>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-row justify="end">
            <el-button type="success" @click="handleQuery">搜索</el-button>
            <el-button class="business resetBtn" @click="resetQuery">重置</el-button>
          </el-row>
        </el-col>
      </el-row>
      <el-row>
        <p class="pinformation">样品列表</p>
        <p class="totalStyle">共 {{ total }} 条数据</p>
      </el-row>
    </el-form>
    <el-table ref="mainTableRef" :data="projectList" v-loading="loading">
      <el-table-column prop="jclbId" label="检测类别" align="center">
        <template #default="scope">
          {{
            scope.row.jclbName
          }}
        </template>
      </el-table-column>
      <el-table-column prop="pointName" label="点位名称" align="center" width="100" />
      <el-table-column prop="sampleCode" label="样品编号" align="center" width="150" />
      <el-table-column prop="jcxmNames" label="检测项目" align="center" width="250" show-overflow-tooltip>
        <template #default="scope">
          <span v-html="transformation(scope.row.jcxmNames)"></span>
        </template>
      </el-table-column>
      <el-table-column prop="sampleDay" label="连测天数" align="center" width="80" />
      <el-table-column prop="sampleCount" label="每天频次" align="center" width="80" />
      <el-table-column prop="" label="特别说明" align="center" />
      <el-table-column label="是否分包" align="center" width="80">
        <template #default="scope">
          {{
            scope.row.isPackage == 0
            ? "否"
            : "是"
          }}
        </template>
      </el-table-column>
      <el-table-column label="容器" align="center" prop="containerTypeId">
        <template #default="scope">
          {{
            proxy.getItemByArray(
              sys_sample_container,
              "value",
              scope.row.containerTypeId,
              "label"
            )
          }}
        </template>
      </el-table-column>
      <el-table-column label="固定剂" align="center" width="250" show-overflow-tooltip>
        <template #default="scope">
          <span v-if="scope.row.fixer">{{
            proxy.getItemByArray(sys_fixer, "value", scope.row.fixer, "label")
          }}
            ,
            {{
              proxy.getItemByArray(
                sys_fixer_desc,
                "value",
                scope.row.fixerDesc,
                "label"
              )
            }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="" label="流量" align="center" />
      <el-table-column prop="saveDesc" label="保存要求" align="center" width="250" show-overflow-tooltip />
      <el-table-column prop="minUse" label="最小用量" align="center" />
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script setup>
import { getFixerList } from "@/api/cyCheck/cyReady";
import { projectListJclb } from "@/api/store/jclb";
const { proxy } = getCurrentInstance();
const loading = ref(false);
const { sys_degree, sys_fixer, sys_fixer_desc, sys_sample_container } =
  proxy.useShareDict(
    "sys_fixer",
    "sys_fixer_desc",
    "sys_degree",
    "sys_sample_container"
  );
const queryParams = ref({
  pageSize: 10,
  pageNum: 1,
  jclbId: -1,
  isPackage: -1
});
const dateRange = ref([]);
const total = ref(0);
const projectList = ref([]);
const jclbList = ref([]);
const isPackageList = ref([
  { value: -1, label: "不限" },
  { value: 0, label: "否" },
  { value: 1, label: "是" },
]);
const props = defineProps({
  projectId: {
    type: String, //参数类型
  },
});

function getId() {
  nextTick(() => {
    queryParams.value.projectId = props.projectId;
    getList();
  });
}

function getList() {
  loading.value = true;
  getFixerList(queryParams.value).then((res) => {
    projectList.value = res.rows;
    total.value = res.total;
    loading.value = false;
  });
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

getId();

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);

const heightParams = ref([{ tableName: "main", bottomHeight: 73 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}
onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
})
onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

function transformation(row) {
  const a = proxy.getSupAndSub(row);
  return a;
}

projectListJclb({ projectId: props.projectId }).then((res) => {
  jclbList.value = res.data;
});
</script>

<style></style>
